from .base_champion import Champion
from typing import Dict, List, Optional


class DragonWarrior(Champion):
    def __init__(self):
        super().__init__(
            name="Dragon Warrior",
            health=150,
            attack=25,
            defense=20,
            speed=15,
            mana=80
        )
    
    def get_abilities(self) -> List[str]:
        return ["Dragon Strike", "Dragon Shield", "Dragon Roar", "Dragon Transformation"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Dragon Strike":
            return self._dragon_strike(target)
        elif ability_name == "Dragon Shield":
            return self._dragon_shield()
        elif ability_name == "Dragon Roar":
            return self._dragon_roar()
        elif ability_name == "Dragon Transformation":
            return self._dragon_transformation()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _dragon_strike(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(20):
            return {"success": False, "message": "Not enough mana"}
        
        damage = int(self.attack * 1.5)
        actual_damage = target.take_damage(damage, "physical")
        
        return {
            "success": True,
            "damage": actual_damage,
            "message": f"{self.name} uses Dragon Strike on {target.name} for {actual_damage} damage!"
        }
    
    def _dragon_shield(self) -> Dict:
        if not self.consume_mana(15):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "defense_boost",
            "value": 10,
            "duration": 3
        })
        
        return {
            "success": True,
            "message": f"{self.name} activates Dragon Shield, gaining +10 defense for 3 turns!"
        }
    
    def _dragon_roar(self) -> Dict:
        if not self.consume_mana(30):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} lets out a mighty Dragon Roar! (Area effect - stuns all enemies)"
        }
    
    def _dragon_transformation(self) -> Dict:
        if not self.consume_mana(50):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "dragon_form",
            "attack_boost": 15,
            "defense_boost": 10,
            "duration": 5
        })
        
        return {
            "success": True,
            "message": f"{self.name} transforms into Dragon Form! +15 attack, +10 defense for 5 turns!"
        }
    
    def get_champion_type(self) -> str:
        return "Warrior"


class TigerStriker(Champion):
    def __init__(self):
        super().__init__(
            name="Tiger Striker",
            health=120,
            attack=30,
            defense=15,
            speed=25,
            mana=90
        )
    
    def get_abilities(self) -> List[str]:
        return ["Tiger Pounce", "Tiger Claws", "Tiger Speed", "Tiger Fury"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Tiger Pounce":
            return self._tiger_pounce(target)
        elif ability_name == "Tiger Claws":
            return self._tiger_claws(target)
        elif ability_name == "Tiger Speed":
            return self._tiger_speed()
        elif ability_name == "Tiger Fury":
            return self._tiger_fury()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _tiger_pounce(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        damage = int(self.attack * 1.3)
        actual_damage = target.take_damage(damage, "physical")
        
        return {
            "success": True,
            "damage": actual_damage,
            "message": f"{self.name} pounces on {target.name} for {actual_damage} damage!"
        }
    
    def _tiger_claws(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(20):
            return {"success": False, "message": "Not enough mana"}
        
        total_damage = 0
        for i in range(3):
            damage = int(self.attack * 0.4)
            actual_damage = target.take_damage(damage, "physical")
            total_damage += actual_damage
        
        return {
            "success": True,
            "damage": total_damage,
            "message": f"{self.name} slashes {target.name} with Tiger Claws for {total_damage} total damage!"
        }
    
    def _tiger_speed(self) -> Dict:
        if not self.consume_mana(15):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "speed_boost",
            "value": 10,
            "duration": 4
        })
        
        return {
            "success": True,
            "message": f"{self.name} activates Tiger Speed, gaining +10 speed for 4 turns!"
        }
    
    def _tiger_fury(self) -> Dict:
        if not self.consume_mana(40):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "tiger_fury",
            "attack_boost": 20,
            "speed_boost": 5,
            "duration": 3
        })
        
        return {
            "success": True,
            "message": f"{self.name} enters Tiger Fury! +20 attack, +5 speed for 3 turns!"
        }
    
    def get_champion_type(self) -> str:
        return "Warrior"


class PhoenixGuardian(Champion):
    def __init__(self):
        super().__init__(
            name="Phoenix Guardian",
            health=180,
            attack=20,
            defense=25,
            speed=10,
            mana=100
        )
    
    def get_abilities(self) -> List[str]:
        return ["Phoenix Shield", "Phoenix Heal", "Phoenix Rebirth", "Phoenix Aura"]
    
    def use_ability(self, ability_name: str, target: Optional[Champion] = None) -> Dict:
        if not self._is_alive:
            return {"success": False, "message": "Cannot use ability - champion is dead"}
        
        if self._is_silenced:
            return {"success": False, "message": f"{self.name} is silenced and cannot use abilities"}
        
        if ability_name == "Phoenix Shield":
            return self._phoenix_shield()
        elif ability_name == "Phoenix Heal":
            return self._phoenix_heal(target)
        elif ability_name == "Phoenix Rebirth":
            return self._phoenix_rebirth()
        elif ability_name == "Phoenix Aura":
            return self._phoenix_aura()
        else:
            return {"success": False, "message": f"Unknown ability: {ability_name}"}
    
    def _phoenix_shield(self) -> Dict:
        if not self.consume_mana(30):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "phoenix_shield",
            "damage_reduction": 50,
            "duration": 3
        })
        
        return {
            "success": True,
            "message": f"{self.name} creates a Phoenix Shield, reducing incoming damage by 50% for 3 turns!"
        }
    
    def _phoenix_heal(self, target: Optional[Champion]) -> Dict:
        if not target or not target.is_alive:
            return {"success": False, "message": "No valid target"}
        
        if not self.consume_mana(25):
            return {"success": False, "message": "Not enough mana"}
        
        heal_amount = 40
        actual_healing = target.heal(heal_amount)
        
        return {
            "success": True,
            "healing": actual_healing,
            "message": f"{self.name} heals {target.name} for {actual_healing} health!"
        }
    
    def _phoenix_rebirth(self) -> Dict:
        if not self.consume_mana(60):
            return {"success": False, "message": "Not enough mana"}
        
        self._buffs.append({
            "type": "phoenix_rebirth",
            "revive_health": self._max_health,
            "duration": 10 
        })
        return {
            "success": True,
            "message": f"{self.name} prepares Phoenix Rebirth - will revive with full health if killed!"
        }
    
    def _phoenix_aura(self) -> Dict:
        if not self.consume_mana(35):
            return {"success": False, "message": "Not enough mana"}
        
        return {
            "success": True,
            "message": f"{self.name} activates Phoenix Aura, buffing all allies! (Area effect)"
        }
    
    def get_champion_type(self) -> str:
        return "Warrior"